package com.hucheng.order.vo;

import com.hucheng.order.entity.GoodsDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.format.DateTimeFormatter;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 返回界面数据
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GoodsVO implements Serializable{
    private Integer goodsId;
    private String goodsName;
    private String goodsTitle;
    private String goodsImg;
    private String goodsDetail;
    private String goodsPrice;
    private String goodsStock;
    private String dateCreated;
    private String dateUpdated;

    public static GoodsVO buildGoodsVO(final GoodsDO goodsDO) {
        if (goodsDO == null) {
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return new GoodsVO(goodsDO.getGoodsId(),goodsDO.getGoodsName(),goodsDO.getGoodsTitle(),goodsDO.getGoodsImg()
        ,goodsDO.getGoodsDetail(),goodsDO.getGoodsPrice(),goodsDO.getGoodsStock(),
                dateTimeFormatter.format(goodsDO.getDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(goodsDO.getDateUpdated().toLocalDateTime()));
    }
}
